//
//  BLBlurEffect.m
//  TimerButton
//
//  Created by Met on 2020/11/8.
//  Copyright © 2020 bill. All rights reserved.
//

#import "BLBlurEffect.h"

// 通过这个扩展自定义effectSettings，取代主类中的effectSettings；
// 也可以简单理解为将主类中的effectSettings暴露出来
@interface UIBlurEffect (BLBlurEffect)
@property (nonatomic, readonly) id effectSettings;
@end

@implementation BLBlurEffect{
    CGFloat _blurRadius;
}

+ (BLBlurEffect *)getEffectWithStyle:(UIBlurEffectStyle)style blurRadius:(CGFloat)radius{
    BLBlurEffect *effect = (BLBlurEffect*)[BLBlurEffect effectWithStyle:style];
    effect->_blurRadius = radius;

    return  effect;
}

+ (BLBlurEffect*)effectWithBlurRadius:(CGFloat)radius{
    return [[BLBlurEffect alloc] initWithRadius:radius];
}

- (BLBlurEffect*)initWithRadius:(CGFloat)radius{
    self = [super init];
    if( self ) {
        _blurRadius = radius;
    }
    return self;
}

///radius 默认是 30、20
- (id)effectSettings {
    // 为了保持除了radius以外的属性不变，需要先把基类的settings取出来
    id settings = [super effectSettings];
//    [settings setValue:@(8) forKey:@"blurRadius"];
    if (_blurRadius <= 0) {_blurRadius = 4.0;}
    [settings setValue:@(_blurRadius) forKey:@"blurRadius"];
    
    return settings;
}

@end
